#ifndef _CENGINE_H
#define _CENGINE_H
#include "global.h"

struct CNode
{
	bool m_On;
	void *m_Data;
};


class CList
{
	public:
		CList();
		~CList();
		
		void Add(void *d);
		void Delete(int n);
		void *Get(int n);
		int Find(void *d);
		int GetLength();
		void Clear();
		
		CNode m_List[255];
		int m_Length;
};

class CTiles
{
	public:
		CTiles();
		~CTiles();
		
		void LoadTile(char *s);
		void ClearTiles();
		void DrawTile(int n,int x,int y);
		
		CList m_Tiles;
};

class CObject
{
	public:
		CObject();
		virtual ~CObject();
		
		virtual void Run();
		virtual void Input(int e);
		virtual void Draw(int p);
		virtual void Clear();
		virtual void Message(int m);
		virtual CObject *SpawnSelf(int x,int y);
		
		bool CollideMap(int x,int y);
		CObject *CollideObject(int n);
		int GetType();
		void Spawn(CObject *o);
		void Die();
		
		int m_X,m_Y;
		int m_SizeX,m_SizeY;
		int m_Tile,m_Type,m_DrawPass;
		bool m_Collide,m_Shown,m_Clear;
};

class CRoom
{
	public:
		CRoom();
		virtual ~CRoom();
		
		virtual void Run();
		virtual void Input(int e);
		virtual void Draw();
		void CenterCamera(int x,int y);
		void Clear();
		
		int m_Map[MAPXSIZE][MAPYSIZE][3];
		int m_XSize,m_YSize;
		int m_CameraX,m_CameraY;
		CList m_Objects;
};

class CGUIText
{
	public:
		CGUIText(char *t,bool m);
		~CGUIText();
		
		char m_Text[80];
		bool m_More;
};

class CGUI
{
	public:
		CGUI();
		~CGUI();
		
		void Draw();
		void DrawBottom();
		void DrawTop();
		
		void ClearBottom();
		void ClearTop();
		void AddBottom(char *s);
		void AddTop(char *s,bool m);
		
		CList m_BottomText;
		CList m_TopText;
};

class CGame
{
	public:
		CGame();
		~CGame();
		
		void Load();
		void LoadObjects();
		void Run();
		void Generate(int sx,int sy,int ox,int oy);
		CObject *GetPlayer();
		CObject *GetType(int t);
		void Title();
		void SpawnObject(int n,int x,int y);
		CObject *AddGroup(char *g,char *g2,char *g3,CObject *o);
		
		CList m_MasterObjects;
		int m_SeenEnemies;
};

class CGroup
{
	public:
		CGroup(char *n) {strncpy(m_Name,n,255);};
		~CGroup() {m_Name[0]=0;};
		
		CList m_Objects;
		char m_Name[255];
};
class CGroups
{
	public:
		CGroups();
		~CGroups();
		
		CObject *Add(char *n,CObject *o);
		CObject *Spawn(char *n,int x,int y);
		void Clear();
		
		CList m_Groups;
};



class CEngine
{
	public:
		CEngine();
		~CEngine();
		
		bool Run();
		void Input();
		void Draw();
		
		CGame m_Game;
		CTiles m_Tiles;
		CGUI m_GUI;
		CList m_Rooms;
		bool m_On;
		CRoom *m_Room;
		CGroups m_Groups;
};



#endif



